/**
 * Copyright 2008-2009 HAN.BIFANG
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package han.bifang.gwt.client.common.util;

public class StringUtils {
	private static String intStr = "0123456789";
	
	public static boolean isEmpty(String s){
		if(s == null || s.trim().length() == 0)
			return true;
		return false;
		
	}
	
	public static boolean checkLenght(String s, int min, int max){
		if(isEmpty(s))
			return false;
		int len = s.length();
		if(len >= min && len <= max ){
			return true;
			
		}
		return false;
		
	}
	
	public static boolean lengthLess(String s, int max){
		if(isEmpty(s))
			return true;
		if(s.length() <= max)
			return true;
		return false;
	}
	
	public static String getIPPORTOfQueryUrl(String queryUrl){
		int index = queryUrl.indexOf("//");
		index = queryUrl.indexOf("/", index + 3);
		return queryUrl.substring(0,index);
		
	}
	public static String getIPPORTOfHttpBinding(String httpUrl){
		int index = httpUrl.indexOf("//");
		index = httpUrl.indexOf("/", index + 3);
		return httpUrl.substring(0,index);
		
	}
	
	public static boolean isInteger(String s){
		if(isEmpty(s))
			return false;
		
		for(int i = 0 , j = s.length(); i < j ; i ++ ){
			char c = s.charAt(i);
			if(intStr.indexOf(c) < 0){
				return false;
			}
		}
		return true;
	}
	
	public static boolean isEmail(String s){
		if(s == null)
			return false;
		if(s.indexOf("@") < 0 || s.indexOf(".") < 0){
			return false;
		}
		return true;
	}
	
	
	
	
}
